#!/usr/bin/bash
#
# Plugin to monitor the number of vulnerabilities on the machine using
# pkg_admin audit.
#
# Parameters:
#
# 	config   (required)
# 	autoconf (optional - used by munin-config)

PKG_ADMIN='/opt/local/sbin/pkg_admin'

if [ "$1" = "autoconf" ]; then
	if [ -x $PKG_ADMIN ]; then
		echo yes 
		exit 0
	else
		echo no '(pkg_admin not found)'
		exit 0
	fi
fi

if [ "$1" = "config" ]; then
	echo 'graph_title Number of Vulnerabilities'
	echo 'graph_args --base 1000 -l 0 '
	echo 'graph_vlabel number of vulnerabilities'
	echo 'graph_category security'
	echo 'graph_info This graph shows the number of vulnerabilities in the system.'
	echo 'vulnerabilities.label vulnerabilities'
	echo 'vulnerabilities.info The current number of vulnerabilities.'
	echo 'vulnerabilities.draw LINE2'
	exit 0
fi

echo -n "vulnerabilities.value "
$PKG_ADMIN audit | awk '{ print $2 }' | uniq | wc -l
